﻿
$(function () {

    teamId = GetQueryString("teamId");
    matchId = GetQueryString("matchId");

    initTeamRemark();

    // 初始化参数
    initParams();

    // 初始化球队名称
    initTeamName();
    
    initLeagueInfos();

    initDetailMatchsTable();

    initTeamLegueInfo();

    $("#recentCount").change(function () {

        initLeagueInfos();
        initDetailMatchsTable();
    });


    // 赛程--主客场点击选择
    $("#hostGuestDiv").children().click(function (obj) {
        $.each($("#hostGuestDiv").children(), function (i, n) {
            if ($(this).hasClass("btn-primary")) {
                $(this).toggleClass("btn-primary").toggleClass("btn-white");
            }
        });

        $(this).toggleClass("btn-white").toggleClass("btn-primary");
        initLeagueInfos();
        initDetailMatchsTable();
    });

    // 总对阵div点击
    $("#playLi").click(function () {

        setTimeout(function () {
            $("#hostTeamTable").chromatable({
                width: "100%",
                height: $("#hostTeamDiv").height(),
                scrolling: "yes"
            });

            $("#guestTeamTable").chromatable({
                width: "100%",
                height: $("#guestTeamDiv").height(),
                scrolling: "yes"
            });

        }, 100);

        //$("#teamLeagues").val(curLeagueId);
       
    });

    // 主客对阵div点击
    $("#playLi2").click(function () {

        setTimeout(function () {
            $("#hostTeamTable2").chromatable({
                width: "100%",
                height: $("#hostTeamDiv2").height(),
                scrolling: "yes"
            });

            $("#guestTeamTable2").chromatable({
                width: "100%",
                height: $("#guestTeamDiv2").height(),
                scrolling: "yes"
            });

        }, 100);

        //$("#teamLeagues").val(curLeagueId);

    });

    // 赛程div点击
    $("#seasonLi").click(function () {
        setTimeout(function () {
            $("#simple-table").chromatable({
                width: "100%",
                height: $("#contentTableDiv").height(),
                scrolling: "yes"
            });

        }, 100);
    });

});


// 首页--初始化球队备注
function initTeamRemark() {

    //$(".save-team").hide();
    $("#editRemark_1").hide();
    $("#editRemark_2").hide();
    $("#editRemark_3").hide();
    $("#showRemark_1").show();
    $("#showRemark_2").show();
    $("#showRemark_3").show();
    $("#btnRemark_1").hide();
    $("#btnRemark_2").hide();
    $("#btnRemark_3").hide();

    $("#teamRemark_1").val("");
    $("#teamRemark_1").val("");
    $("#teamRemark_1").val("");
    $("#showRemark_1>p").html("");
    $("#showRemark_2>p").html("");
    $("#showRemark_3>p").html("");

    var postData = {
        "teamId": teamId
    };

    $.ajax({
        type: "Post",
        url: "/RealTimeMatchs/GetTeamRemarkInfo",
        data: postData,
        success: function (d) {
            if (d.success) {
                var data = d.data;
                if (data != null && data.length > 0) {

                    for (var i = 0; i < data.length; i++) {
                        var value = data[i].teamRemark == null ? "" : data[i].teamRemark;
                        $("#teamRemark_" + data[i].appUserIndex).val(value);
                        if (value == "") {
                            $("#showRemark_" + data[i].appUserIndex + ">p").html("");
                        } else {
                            value = value.replace(/\n/g, "</p><p>");
                            value = value.replace(/\s/g,"&nbsp;");
                            
                            $("#showRemark_" + data[i].appUserIndex + ">p").html("" + value + "");
                        }
                        
                        $("#editUser_" + data[i].appUserIndex).html("分析师："+data[i].appUserName);
                        if (data[i].isEdit == 1) {
                            initRemark = data[i].teamRemark;
                            $("#btnRemark_" + data[i].appUserIndex).show();
                            //$("#showRemark_" + data[i].appUserIndex).hide();
                            //$("#editRemark_" + data[i].appUserIndex).show();
                        } 
                    }
                    
                }
               
            }
        }
    });

}

// 首页--保存球队备注
function saveTeamRemark(userIndex) {
    var postData = {
        "teamRemarkInfo":
            {
                "TeamId": teamId,
                "TeamName": teamName,
                "TeamRemark": $("#teamRemark_"+userIndex).val()
            }
    };

    $.ajax({
        type: "Post",
        url: "/RealTimeMatchs/EditTeamRemark",
        data: postData,
        success: function (d) {
            layer.msg(d.message);
            if (d.success) {
                var value = $("#teamRemark_" + userIndex).val();
                if (value == "" ) {
                    $("#showRemark_" + userIndex + ">p").html("");
                } else {
                    value = value.replace(/\n/g, "</p><p>");
                    value = value.replace(/\s/g, "&nbsp;");
                    $("#showRemark_" + userIndex + ">p").html("" + value + "");
                }
                
                initRemark = $("#teamRemark_" + userIndex).val();

                $("#showRemark_" + userIndex).show();
                $("#editRemark_" + userIndex).hide();

                $("#btnEdit_" + userIndex).val("0");
                $("#btnEdit_" + userIndex).html("编辑");
                $("#btnEdit_" + userIndex).next().hide();
            }
        }
    });
}


var initRemark = "";
// 首页--编辑球队备注
function editTeamRemark(obj, userIndex) {
    var editTag = $(obj).val();
    if (editTag == "0") { // 编辑
        $(obj).val("1");
        $(obj).html("放弃");
        $(obj).next().show();
        //$("#teamRemark_" + userIndex).removeAttr("readonly");
        
        $("#showRemark_" + userIndex).hide();
        $("#editRemark_" + userIndex).show();
        $("#teamRemark_" + userIndex).focus();

    } else { // 放弃
        $(obj).val("0");
        $(obj).html("编辑");
        $(obj).next().hide();
        $("#teamRemark_" + userIndex).val(initRemark);
        //$("#teamRemark_" + userIndex).attr("readonly", "readonly");
        $("#showRemark_" + userIndex).show();
        $("#editRemark_" + userIndex).hide();
    }
    
}

// 初始化高度
function initParams() {
    var playHeight = $(window).height() - 130;
    $("#playDiv").height(playHeight);
    $("#detailContent").height(playHeight - 60);
    $("#contentTableDiv").height(playHeight - 114);
    $("#recentCount").val(30);

    $("#hostTeamDiv").height(playHeight - 150);
    $("#guestTeamDiv").height(playHeight - 150);

    $("#hostTeamDiv2").height(playHeight - 155);
    $("#guestTeamDiv2").height(playHeight - 155);

    $.each($("#hostGuestDiv").children(), function (i, n) {
        if ($(this).hasClass("btn-primary")) {
            $(this).toggleClass("btn-primary").toggleClass("btn-white");
        }
    });

    $("#hostGuestDiv > button:first").toggleClass("btn-white").toggleClass("btn-primary");
}


// 获取请求参数值
function GetQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]); return null;
}


var teamId = -1;
var matchId = -1;
var teamMatchList = [];
var teamName = "";

// 赛程--赛事复选
function changeLeagueInfo(){
    var chk_value = [];
    $('input[name="leagueIds"]:checked').each(function () {
        chk_value.push($(this).val());
    });
    $("#detailMatchTable").html('');
    if (chk_value.length < 1) return;
    var tabStr = '';
    var data = teamMatchList;
    for (var i = 0; i < data.length; i++) {

        var leagueId = data[i].leagueId;
        var flag = false;
        for (var j = 0; j < chk_value.length; j++) {
            if (chk_value[j] == leagueId) {
                flag = true;
                break;
            }
        }

        if (!flag) continue;

        tabStr += '<tr>';
        tabStr += '<td class="center">' + (i + 1) + '</td>';
        tabStr += '<td class="center">' + data[i].leagueName + '</td>';
        tabStr += '<td class="center">' + data[i].matchTime + '</td>';
        if (teamId == data[i].hostTeamId) {
            tabStr += '<td class="center">' + showTeamName(data[i].hostTeamId, data[i].hostTeamName) + '</td>';
        } else {
            tabStr += '<td class="center"><a target="_blank" href="../TeamPlayInfo?teamId=' + data[i].hostTeamId + '&matchId=' + data[i].matchId + '">' + showTeamName(data[i].hostTeamId, data[i].hostTeamName) + '</a></td>';
        }
        
        tabStr += '<td class="center">' + swapScores(data[i].hostScore, data[i].guestScore, data[i].hostHalfScore, data[i].guestHalfScore) + '</td>';

        if (teamId == data[i].guestTeamId) {
            tabStr += '<td class="center">' + showTeamName(data[i].guestTeamId, data[i].guestTeamName) + '</td>';
        } else {
            tabStr += '<td class="center"><a target="_blank" href="../TeamPlayInfo?teamId=' + data[i].guestTeamId + '&matchId=' + data[i].matchId + '">' + showTeamName(data[i].guestTeamId, data[i].guestTeamName) + '</a></td>';
        }
        
        tabStr += '<td class="center">' + getWinOrLose(data[i].hostTeamId, data[i].guestTeamId, data[i].hostScore, data[i].guestScore) + '</td>';
        tabStr += '<td class="center">' + swapOdds(data[i].winOdds, data[i].hostScore, data[i].guestScore, 3) + '</td>';
        tabStr += '<td class="center">' + swapOdds(data[i].drowOdds, data[i].hostScore, data[i].guestScore, 1) + '</td>';
        tabStr += '<td class="center">' + swapOdds(data[i].loseOdds, data[i].hostScore, data[i].guestScore, 0) + '</td>';
        tabStr += '<td class="center"><a href="http://odds.500.com/fenxi/shuju-' + data[i].matchId + '.shtml" target="view_window">析</a></td>';
        tabStr += '</tr>';
    }

    $("#detailMatchTable").html(tabStr);

    $("#simple-table").chromatable({
        width: "100%",
        height: $("#contentTableDiv").height(),
        scrolling: "yes"
    });
}


/**
 *  赛程--初始化赛事信息
 */
function initLeagueInfos() {
    var recentCount = $("#recentCount").val();
    var hostOrGuest = $("#hostGuestDiv").find(".btn-primary").attr("data-value");

    var postData = {
        "param":
            {
                "TeamId": teamId,
                "RecentMatchCount": recentCount,
                "HostOrGuest": hostOrGuest
            }
    };

    $.ajax({
        type: "Post",
        url: "/RealTimeMatchs/GetLeaguesByParam",
        data: postData,
        success: function (d) {
            if (d.success) {
                //$(".ui-dialog-titlebar-close:eq(0)").trigger("click");
                var data = d.data;
                $("#leagueIdsLabel").html("");
                var str = '';
                for (var i = 0; i < data.length; i++) {
                    str += '<input type="checkbox" checked="checked" value="' + data[i].leagueId + '" name="leagueIds" />' + (data[i].leagueName == null || data[i].leagueName=="" ? "无" : data[i].leagueName) + '&nbsp;&nbsp;';
                }
                $("#leagueIdsLabel").html(str);

                $('input[name="leagueIds"]').on("change",changeLeagueInfo);
            } 
        }
    });

}

// 赛程--获取比赛记录并构建表格
function initDetailMatchsTable() {
    var recentCount = $("#recentCount").val();
    var hostOrGuest = $("#hostGuestDiv").find(".btn-primary").attr("data-value");

    var postData = {
        "param":
            {
                "TeamId": teamId,
                "RecentMatchCount": recentCount,
                "HostOrGuest": hostOrGuest
            }
    };

    $.ajax({
        type: "Post",
        url: "/RealTimeMatchs/GetMatchsByTeamParam",
        data: postData,
        success: function (d) {
            if (d.success) {
                var data = d.data;
                teamMatchList = data;

                writeContentTable(data);
                
            }
        }
    });
}


// 赛程--构建球队历史比赛记录表格
function writeContentTable(data) {
    $("#detailMatchTable").html('');
    var tabStr = '';
    for (var i = 0; i < data.length; i++) {
        tabStr += '<tr>';
        tabStr += '<td class="center">' + (i + 1) + '</td>';
        tabStr += '<td class="center">' + data[i].leagueName + '</td>';
        tabStr += '<td class="center">' + data[i].matchTime + '</td>';

        if (teamId == data[i].hostTeamId) {
            tabStr += '<td class="center">' + showTeamName(data[i].hostTeamId, data[i].hostTeamName) + '</td>';
        } else {
            tabStr += '<td class="center"><a target="_blank" href="../TeamPlayInfo?teamId=' + data[i].hostTeamId + '&matchId=' + data[i].matchId + '">' + showTeamName(data[i].hostTeamId, data[i].hostTeamName) + '</a></td>';
        }

        tabStr += '<td class="center">' + swapScores(data[i].hostScore, data[i].guestScore, data[i].hostHalfScore, data[i].guestHalfScore) + '</td>';

        if (teamId == data[i].guestTeamId) {
            tabStr += '<td class="center">' + showTeamName(data[i].guestTeamId, data[i].guestTeamName) + '</td>';
        } else {
            tabStr += '<td class="center"><a target="_blank" href="../TeamPlayInfo?teamId=' + data[i].guestTeamId + '&matchId=' + data[i].matchId + '">' + showTeamName(data[i].guestTeamId, data[i].guestTeamName) + '</a></td>';
        }

        tabStr += '<td class="center">' + getWinOrLose(data[i].hostTeamId, data[i].guestTeamId, data[i].hostScore, data[i].guestScore) + '</td>';
        tabStr += '<td class="center">' + swapOdds(data[i].winOdds, data[i].hostScore, data[i].guestScore, 3) + '</td>';
        tabStr += '<td class="center">' + swapOdds(data[i].drowOdds, data[i].hostScore, data[i].guestScore, 1) + '</td>';
        tabStr += '<td class="center">' + swapOdds(data[i].loseOdds, data[i].hostScore, data[i].guestScore, 0) + '</td>';
        tabStr += '<td class="center"><a href="http://odds.500.com/fenxi/shuju-' + data[i].matchId + '.shtml" target="view_window">析</a></td>';
        tabStr += '</tr>';
    }

    $("#detailMatchTable").html(tabStr);

    $("#simple-table").chromatable({
        width: "100%",
        height: $("#contentTableDiv").height(),
        scrolling: "yes"
    });
}


// 主对阵--切换赛事下拉选择框
function changeTeamLeagueInfo() {
    curLeagueId = $("#teamLeagues").val();
    initSeasonInfo();
   
}

// 主客对阵--切换赛事
function changeTeamLeagueInfo2() {
    curLeagueId2 = $("#teamLeagues2").val();
    initSeasonInfo2();
}

// 总对阵--切换赛季下拉选择框
function changeTeamSeasonInfo() {
    curSeasonId = $("#teamSeasons").val();
    curLastSeasonId = curSeasonId;
    $("#lastSeasons").val(curLastSeasonId);
    //changeLastSeasonInfo();
    initTeamInfo();
    initTeamRankInfo();
}

// 总对阵--切换对阵赛季
function changeLastSeasonInfo() {
    curLastSeasonId = $("#lastSeasons").val();
    initTeamInfo();
    //initTeamRankInfo();
}


// 主客对阵--切换赛季下拉选择框
function changeTeamSeasonInfo2() {
    curSeasonId2 = $("#teamSeasons2").val();
    curLastSeasonId2 = curSeasonId2;
    $("#lastSeasons2").val(curLastSeasonId2);
    //changeLastSeasonInfo2();
    initTeamInfo2();
    initTeamRankInfo2();
}

// 主客对阵--切换对阵赛季
function changeLastSeasonInfo2() {
    curLastSeasonId2 = $("#lastSeasons2").val();
    initTeamInfo2();
    //initTeamRankInfo2();
}


// 总对阵--初始化球队赛季排名信息
function initTeamRankInfo() {
    var postData = {
        "param":
            {
                "TeamId": teamId,
                "LeagueId": curLeagueId,
                "SeasonId": curSeasonId
            }
    };

    $("#teamRankSpan").html("");
    $("#hostRankSpan").html("");
    $("#teamRankSpan").html("");

    $.ajax({
        type: "Post",
        url: "/RealTimeMatchs/GetTeamRankInfo",
        data: postData,
        success: function (d) {
            if (d.success) {
                var data = d.data;
                // 总对阵
               
                if (data != undefined && data != null && data != '') {
                    var str = '';
                    str = '<table class="table table-condensed table-bordered">';
                    str += '<tr><td>当前赛季</td>';
                    str += '<td >赛 ' + data.allCount + '</td>';
                    str += '<td >胜 ' + data.winCount + '</td>';
                    str += '<td >平 ' + data.drawCount + '</td>';
                    str += '<td >负 ' + data.loseCount + '</td>';
                    str += '<td >进球 ' + data.inCount + '</td>';
                    str += '<td >失球 ' + data.outCount + '</td>';
                    str += '<td >净胜 ' + data.goalCount + '</td>';
                    str += '<td >积分 <font style="color:red;">' + data.teamIntegral + '</font></td>';
                    str += '<td >排名 ' + data.teamRank + '</td></tr>';
                    str += '<table>';
                    $("#teamRankSpan").html(str);

                    var str = '<table class="table table-condensed table-bordered">';
                    str += '<tr><td>客场表现</td>';
                    str += '<td >赛 ' + data.guestAllCount + '</td>';
                    str += '<td >胜 ' + data.guestWinCount + '</td>';
                    str += '<td >平 ' + data.guestDrawCount + '</td>';
                    str += '<td >负 ' + data.guestLoseCount + '</td>';
                    str += '<td >进球 ' + data.guestInCount + '</td>';
                    str += '<td >失球 ' + data.guestOutCount + '</td>';
                    str += '<td >净胜 ' + data.guestGoalCount + '</td>';
                    str += '<td >积分 <font style="color:red;">' + data.guestIntegral + '</font></td>';
                    str += '<td >排名 ' + data.guestRank + '</td></tr>';
                    str += '<table>';
                    $("#guestRankSpan").html(str);

                    str = '<table class="table table-condensed table-bordered">';
                    str += '<tr><td>主场表现</td>';
                    str += '<td >赛 ' + data.hostAllCount + '</td>';
                    str += '<td >胜 ' + data.hostWinCount + '</td>';
                    str += '<td >平 ' + data.hostDrawCount + '</td>';
                    str += '<td >负 ' + data.hostLoseCount + '</td>';
                    str += '<td >进球 ' + data.hostInCount + '</td>';
                    str += '<td >失球 ' + data.hostOutCount + '</td>';
                    str += '<td >净胜 ' + data.hostGoalCount + '</td>';
                    str += '<td >积分 <font style="color:red;">' + data.hostIntegral + '</font></td>';
                    str += '<td >排名 ' + data.hostRank + '</td></tr>';
                    str += '<table>';
                    $("#hostRankSpan").html(str);
                } 

            }
        }
    });
}

// 主客对阵--初始化球队赛季排名信息
function initTeamRankInfo2() {

    postData = {
        "param":
            {
                "TeamId": teamId,
                "LeagueId": curLeagueId2,
                "SeasonId": curSeasonId2
            }
    };

    $("#teamRankSpan2").html("");
    $("#hostRankSpan2").html("");
    $("#teamRankSpan2").html("");

    $.ajax({
        type: "Post",
        url: "/RealTimeMatchs/GetTeamRankInfo",
        data: postData,
        success: function (d) {
            if (d.success) {
                var data = d.data;

                if (data != undefined && data != null && data != '') {

                    var str = '<table class="table table-condensed table-bordered">';
                    str += '<tr><td>当前赛季</td>';
                    str += '<td >赛 ' + data.allCount + '</td>';
                    str += '<td >胜 ' + data.winCount + '</td>';
                    str += '<td >平 ' + data.drawCount + '</td>';
                    str += '<td >负 ' + data.loseCount + '</td>';
                    str += '<td >进球 ' + data.inCount + '</td>';
                    str += '<td >失球 ' + data.outCount + '</td>';
                    str += '<td >净胜 ' + data.goalCount + '</td>';
                    str += '<td >积分 <font style="color:red;">' + data.teamIntegral + '</font></td>';
                    str += '<td >排名 ' + data.teamRank + '</td></tr>';
                    str += '<table>';

                    $("#teamRankSpan2").html(str);

                    var str = '<table class="table table-condensed table-bordered">';
                    str += '<tr><td>客场表现</td>';
                    str += '<td >赛 ' + data.guestAllCount + '</td>';
                    str += '<td >胜 ' + data.guestWinCount + '</td>';
                    str += '<td >平 ' + data.guestDrawCount + '</td>';
                    str += '<td >负 ' + data.guestLoseCount + '</td>';
                    str += '<td >进球 ' + data.guestInCount + '</td>';
                    str += '<td >失球 ' + data.guestOutCount + '</td>';
                    str += '<td >净胜 ' + data.guestGoalCount + '</td>';
                    str += '<td >积分 <font style="color:red;">' + data.guestIntegral + '</font></td>';
                    str += '<td >排名 ' + data.guestRank + '</td></tr>';
                    str += '<table>';
                    $("#guestRankSpan2").html(str);

                    str = '<table class="table table-condensed table-bordered">';
                    str += '<tr><td>主场表现</td>';
                    str += '<td >赛 ' + data.hostAllCount + '</td>';
                    str += '<td >胜 ' + data.hostWinCount + '</td>';
                    str += '<td >平 ' + data.hostDrawCount + '</td>';
                    str += '<td >负 ' + data.hostLoseCount + '</td>';
                    str += '<td >进球 ' + data.hostInCount + '</td>';
                    str += '<td >失球 ' + data.hostOutCount + '</td>';
                    str += '<td >净胜 ' + data.hostGoalCount + '</td>';
                    str += '<td >积分 <font style="color:red;">' + data.hostIntegral + '</font></td>';
                    str += '<td >排名 ' + data.hostRank + '</td></tr>';
                    str += '<table>';
                    $("#hostRankSpan2").html(str);

                } 

            }
        }
    });
}


// 初始化球队名称，当前赛事信息
function initTeamName(){
    var postData = {
        "param":
            {
                "TeamId": teamId,
                "MatchId": matchId,
                "HostOrGuest": 0
            }
    };

    $.ajax({
        type: "Post",
        url: "/RealTimeMatchs/GetAllMatchsByTeamParam",
        data: postData,
        success: function (d) {
            if (d.success) {
                var data = d.data;
                if (data != null && data != "" && data.length > 0) {
                    curLeagueId = data[0].leagueId;
                    curLeagueId2 = data[0].leagueId;

                    if (data[0].hostTeamId == teamId) {
                        $("#titleName").html(data[0].hostTeamName);
                        $(document).attr("title", data[0].hostTeamName);
                        teamName = data[0].hostTeamName;
                    } else {
                        $("#titleName").html(data[0].guestTeamName);
                        $(document).attr("title", data[0].guestTeamName);
                        teamName = data[0].guestTeamName;
                    }
                }
                
                
            }
        }
    });

}

var curLeagueId = 0;
var curSeasonId = 0;
var curLastSeasonId = 0;
var curLeagueId2 = 0;
var curSeasonId2 = 0;
var curLastSeasonId2 = 0;

// 总对阵与主客对阵--初始化球队所有赛事信息
function initTeamLegueInfo() {
    var postData = {
        "param":
            {
                "TeamId": teamId
            }
    };

    $.ajax({
        type: "Post",
        url: "/RealTimeMatchs/GetTeamLeagues",
        data: postData,
        success: function (d) {
            if (d.success) {
                var data = d.data;
                // 总对阵
                $("#teamLeagues").html("");
                // 主客对阵
                $("#teamLeagues2").html("");

                var str = "";
                if (curLeagueId < 1) {
                    curLeagueId = data[0].leagueId;
                    curLeagueId2 = data[0].leagueId;
                }
                
                for (var i = 0; i < data.length; i++) {
                    if (curLeagueId == data[i].leagueId) {
                        str += '<option value="' + data[i].leagueId + '" selected >' + data[i].leagueName + '</option>';
                    } else {
                        str += '<option value="' + data[i].leagueId + '">' + data[i].leagueName + '</option>';
                    }
                }

                // 总对阵
                $("#teamLeagues").html(str);
                // 主客对阵
                $("#teamLeagues2").html(str);

                initSeasonInfo();
                initSeasonInfo2();

                // 绑定赛事切换处理事件，总对阵
                $("#teamLeagues").on("change", changeTeamLeagueInfo);
                // 绑定赛事切换处理事件，主客对阵
                $("#teamLeagues2").on("change", changeTeamLeagueInfo2);
            }
        }
    });
}

// 总对阵--初始化当前球队赛事下参赛赛季
function initSeasonInfo() {
    var postData = {
        "param":
            {
                "TeamId": teamId,
                "HostOrGuest": 0,
                "LeagueId": curLeagueId
            }
    };

    $.ajax({
        type: "Post",
        url: "/RealTimeMatchs/GetTeamSeasons",
        data: postData,
        success: function (d) {
            if (d.success) {
                var data = d.data;

                // 总对阵
                $("#teamSeasons").html("");

                var str = "";

                for (var i = 0; i < data.length; i++) {
                    str += '<option value="' + data[i].seasonId + '">' + data[i].seasonName + '</option>';
                }

                // 总对阵
                $("#teamSeasons").html(str);


                // 绑定赛季切换处理事件，总对阵
                $("#teamSeasons").on("change", changeTeamSeasonInfo);

                initLastSeasonInfo();
               
            }
        }
    });

}

// 总对阵--初始化赛事所有赛季
function initLastSeasonInfo() {

    var postData = {
        "param":
            {
                "LeagueId": curLeagueId
            }
    };

    $.ajax({
        type: "Post",
        url: "/RealTimeMatchs/GetSeasonsByParam",
        data: postData,
        success: function (d) {
            if (d.success) {
                var data = d.data;

                // 总对阵
                $("#lastSeasons").html("");
                var str = "";

                curSeasonId = $("#teamSeasons").val();
                for (var i = 0; i < data.length; i++) {
                    if (curSeasonId == data[i].seasonId) {
                        str += '<option value="' + data[i].seasonId + '" selected="selected">' + data[i].seasonName + '</option>';
                    } else {
                        str += '<option value="' + data[i].seasonId + '">' + data[i].seasonName + '</option>';
                    }
                     
                }

                // 总对阵
                $("#lastSeasons").html(str);

                // 初始化总对阵球队信息表格

                curLastSeasonId = curSeasonId;
                
                initTeamInfo();
                initTeamRankInfo();

                // 绑定赛季切换处理事件，总对阵
                $("#lastSeasons").on("change", changeLastSeasonInfo);

            }
        }
    });

    
}


// 主客对阵--初始化球队赛事的赛季信息
function initSeasonInfo2() {
    var postData = {
        "param":
            {
                "TeamId": teamId,
                "HostOrGuest":0,
                "LeagueId": curLeagueId2
            }
    };

    $.ajax({
        type: "Post",
        url: "/RealTimeMatchs/GetTeamSeasons",
        data: postData,
        success: function (d) {
            if (d.success) {
                var data = d.data;
                // 主客对阵
                $("#teamSeasons2").html("");

                var str = "";

                for (var i = 0; i < data.length; i++) {
                    str += '<option value="' + data[i].seasonId + '">' + data[i].seasonName + '</option>';
                }
               
                // 主客对阵
                $("#teamSeasons2").html(str);


                // 绑定赛季切换处理事件，主客对阵
                $("#teamSeasons2").on("change", changeTeamSeasonInfo2);

                initLastSeasonInfo2();

            }
        }
    });

}

// 主客对阵--初始化赛事所有赛季
function initLastSeasonInfo2() {
    var postData = {
        "param":
            {
                "LeagueId": curLeagueId2
            }
    };
    $.ajax({
        type: "Post",
        url: "/RealTimeMatchs/GetSeasonsByParam",
        data: postData,
        success: function (d) {
            if (d.success) {
                var data = d.data;
                // 主客对阵
                $("#lastSeasons2").html("");

                var str = "";
                curSeasonId2 = $("#teamSeasons2").val();

                for (var i = 0; i < data.length; i++) {
                    if (curSeasonId2 == data[i].seasonId) {
                        str += '<option value="' + data[i].seasonId + '" selected="selected">' + data[i].seasonName + '</option>';
                    } else {
                        str += '<option value="' + data[i].seasonId + '">' + data[i].seasonName + '</option>';
                    }
                }

                // 主客对阵
                $("#lastSeasons2").html(str);

                
                curLastSeasonId2 = curSeasonId2;

                initTeamInfo2();
                initTeamRankInfo2();

                // 绑定赛季切换处理事件，主客对阵
                $("#lastSeasons2").on("change", changeLastSeasonInfo2);
                
            }
        }
    });
}



// 总对阵--初始化球队对阵信息
function initTeamInfo() {

    // 主场
    var postData = {
        "param":
            {
                "TeamId": teamId,
                "LeagueId": curLeagueId,
                "SeasonId": curSeasonId,
                "LastSeasonId": curLastSeasonId,
                "HostOrGuest":1
            }
    };

    $("#detailHostTeamTable").html("");

    $.ajax({
        type: "Post",
        url: "/RealTimeMatchs/GetMatchTeamInfos",
        data: postData,
        success: function (d) {
            if (d.success) {
                var data = d.data;
                var tabStr = '';
                var tempId = -1;
                for (var i = 0; i < data.length; i++) {
                    tabStr += '<tr>';
                    tabStr += '<td class="center">' + (i + 1) + '</td>';
                    tabStr += '<td class="center">' + data[i].matchTime + '</td>';
                    tabStr += '<td class="center"><a target="_blank" href="../TeamPlayInfo?teamId=' + data[i].guestTeamId + '&matchId=' + data[i].matchId + '">' + showTeamName(data[i].guestTeamId, data[i].guestTeamName) + '</a>[' + (data[i].teamRank == 9999 ? "无" : data[i].teamRank) + ']</td>';
                    tabStr += '<td class="center">' + swapScores(data[i].hostScore, data[i].guestScore, data[i].hostHalfScore, data[i].guestHalfScore) + '</td>';
                    tabStr += '<td class="center">' + getWinOrLose(data[i].hostTeamId, data[i].guestTeamId, data[i].hostScore, data[i].guestScore) + '</td>';
                    tabStr += '<td class="center">' + swapOdds(data[i].winOdds, data[i].hostScore, data[i].guestScore, 3) + '</td>';
                    tabStr += '<td class="center">' + swapOdds(data[i].drowOdds, data[i].hostScore, data[i].guestScore, 1) + '</td>';
                    tabStr += '<td class="center">' + swapOdds(data[i].loseOdds, data[i].hostScore, data[i].guestScore, 0) + '</td>';
                    if (tempId != data[i].guestTeamId) {
                        tabStr += '<td class="center">' + data[i].allCount + '</td>';
                        tabStr += '<td class="center">' + data[i].winCount + '</td>';
                        tabStr += '<td class="center">' + data[i].drawCount + '</td>';
                        tabStr += '<td class="center">' + data[i].loseCount + '</td>';
                        tabStr += '<td class="center">' + data[i].inCount + '</td>';
                        tabStr += '<td class="center">' + data[i].outCount + '</td>';
                        tabStr += '<td class="center">' + data[i].goalCount + '</td>';
                        tabStr += '<td class="center"><font style="color:red;">' + data[i].teamIntegral + '</font></td>';
                        
                    } else {
                        tabStr += '<td class="center"></td>';
                        tabStr += '<td class="center"></td>';
                        tabStr += '<td class="center"></td>';
                        tabStr += '<td class="center"></td>';
                        tabStr += '<td class="center"></td>';
                        tabStr += '<td class="center"></td>';
                        tabStr += '<td class="center"></td>';
                        tabStr += '<td class="center"></td>';

                    }
                    tempId = data[i].guestTeamId;

                    tabStr += '<td class="center"><a href="http://odds.500.com/fenxi/shuju-' + data[i].matchId + '.shtml" target="view_window">析</a></td>';
                    tabStr += '</tr>';
                }

                $("#detailHostTeamTable").html(tabStr);

                $("#hostTeamTable").chromatable({
                    width: "100%",
                    height: $("#hostTeamDiv").height(),
                    scrolling: "yes"
                });
                
            }
        }
    });

    // 客场
    postData = {
        "param":
            {
                "TeamId": teamId,
                "LeagueId": curLeagueId,
                "SeasonId": curSeasonId,
                "LastSeasonId": curLastSeasonId,
                "HostOrGuest": 2
            }
    };

    $("#detailGuestTeamTable").html("");

    $.ajax({
        type: "Post",
        url: "/RealTimeMatchs/GetMatchTeamInfos",
        data: postData,
        success: function (d) {
            if (d.success) {
                var data = d.data;
                var tabStr = '';
                var tempId = -1;
                for (var i = 0; i < data.length; i++) {
                    tabStr += '<tr>';
                    tabStr += '<td class="center">' + (i + 1) + '</td>';
                    tabStr += '<td class="center">' + data[i].matchTime + '</td>';
                    tabStr += '<td class="center"><a target="_blank" href="../TeamPlayInfo?teamId=' + data[i].hostTeamId + '&matchId=' + data[i].matchId + '">' + showTeamName(data[i].hostTeamId, data[i].hostTeamName) + '</a>[' + (data[i].teamRank == 9999 ? "无" : data[i].teamRank) +']</td>';
                    tabStr += '<td class="center">' + swapScores(data[i].hostScore, data[i].guestScore, data[i].hostHalfScore, data[i].guestHalfScore) + '</td>';
                    tabStr += '<td class="center">' + getWinOrLose(data[i].hostTeamId, data[i].guestTeamId, data[i].hostScore, data[i].guestScore) + '</td>';
                    tabStr += '<td class="center">' + swapOdds(data[i].winOdds, data[i].hostScore, data[i].guestScore, 3) + '</td>';
                    tabStr += '<td class="center">' + swapOdds(data[i].drowOdds, data[i].hostScore, data[i].guestScore, 1) + '</td>';
                    tabStr += '<td class="center">' + swapOdds(data[i].loseOdds, data[i].hostScore, data[i].guestScore, 0) + '</td>';
                    if (tempId != data[i].hostTeamId) {
                        tabStr += '<td class="center">' + data[i].allCount + '</td>';
                        tabStr += '<td class="center">' + data[i].winCount + '</td>';
                        tabStr += '<td class="center">' + data[i].drawCount + '</td>';
                        tabStr += '<td class="center">' + data[i].loseCount + '</td>';
                        tabStr += '<td class="center">' + data[i].inCount + '</td>';
                        tabStr += '<td class="center">' + data[i].outCount + '</td>';
                        tabStr += '<td class="center">' + data[i].goalCount + '</td>';
                        tabStr += '<td class="center"><font style="color:red;">' + data[i].teamIntegral + '</font></td>';

                    } else {
                        tabStr += '<td class="center"></td>';
                        tabStr += '<td class="center"></td>';
                        tabStr += '<td class="center"></td>';
                        tabStr += '<td class="center"></td>';
                        tabStr += '<td class="center"></td>';
                        tabStr += '<td class="center"></td>';
                        tabStr += '<td class="center"></td>';
                        tabStr += '<td class="center"></td>';

                    }
                    tempId = data[i].hostTeamId;

                    tabStr += '<td class="center"><a href="http://odds.500.com/fenxi/shuju-' + data[i].matchId + '.shtml" target="view_window">析</a></td>';
                    tabStr += '</tr>';
                }

                $("#detailGuestTeamTable").html(tabStr);

                $("#guestTeamTable").chromatable({
                    width: "100%",
                    height: $("#guestTeamDiv").height(),
                    scrolling: "yes"
                });
               
            }
        }
    });
}


// 主客对阵--初始化球队对阵信息
function initTeamInfo2() {

    // 主场
    var postData = {
        "param":
            {
                "TeamId": teamId,
                "LeagueId": curLeagueId2,
                "SeasonId": curSeasonId2,
                "LastSeasonId": curLastSeasonId2,
                "HostOrGuest": 1
            }
    };

    $("#detailHostTeamTable2").html("");

    $.ajax({
        type: "Post",
        url: "/RealTimeMatchs/GetNewMatchTeamInfos",
        data: postData,
        success: function (d) {
            if (d.success) {
                var data = d.data;
                var tabStr = '';
                var tempId = -1;
                for (var i = 0; i < data.length; i++) {
                    tabStr += '<tr>';
                    tabStr += '<td class="center">' + (i + 1) + '</td>';
                    tabStr += '<td class="center">' + data[i].matchTime + '</td>';
                    tabStr += '<td class="center"><a target="_blank" href="../TeamPlayInfo?teamId=' + data[i].guestTeamId + '&matchId=' + data[i].matchId + '">' + showTeamName(data[i].guestTeamId, data[i].guestTeamName) + '</a>[' + (data[i].guestTeamRank == 9999?"无":data[i].guestTeamRank) + ']</td>';
                    tabStr += '<td class="center">' + swapScores(data[i].hostScore, data[i].guestScore, data[i].hostHalfScore, data[i].guestHalfScore) + '</td>';
                    tabStr += '<td class="center">' + getWinOrLose(data[i].hostTeamId, data[i].guestTeamId, data[i].hostScore, data[i].guestScore) + '</td>';
                    tabStr += '<td class="center">' + swapOdds(data[i].winOdds, data[i].hostScore, data[i].guestScore, 3) + '</td>';
                    tabStr += '<td class="center">' + swapOdds(data[i].drowOdds, data[i].hostScore, data[i].guestScore, 1) + '</td>';
                    tabStr += '<td class="center">' + swapOdds(data[i].loseOdds, data[i].hostScore, data[i].guestScore, 0) + '</td>';
                    if (tempId != data[i].guestTeamId) {
                        tabStr += '<td class="center">' + data[i].guestAllCount + '</td>';
                        tabStr += '<td class="center">' + data[i].guestWinCount + '</td>';
                        tabStr += '<td class="center">' + data[i].guestDrawCount + '</td>';
                        tabStr += '<td class="center">' + data[i].guestLoseCount + '</td>';
                        tabStr += '<td class="center">' + data[i].guestInCount + '</td>';
                        tabStr += '<td class="center">' + data[i].guestOutCount + '</td>';
                        tabStr += '<td class="center">' + data[i].guestGoalCount + '</td>';
                        tabStr += '<td class="center"><font style="color:red;">' + data[i].guestIntegral + '</font></td>';
                    } else {
                        tabStr += '<td class="center"></td>';
                        tabStr += '<td class="center"></td>';
                        tabStr += '<td class="center"></td>';
                        tabStr += '<td class="center"></td>';
                        tabStr += '<td class="center"></td>';
                        tabStr += '<td class="center"></td>';
                        tabStr += '<td class="center"></td>';
                        tabStr += '<td class="center"></td>';
                    }
                    tempId = data[i].guestTeamId;
                    
                    tabStr += '<td class="center"><a href="http://odds.500.com/fenxi/shuju-' + data[i].matchId + '.shtml" target="view_window">析</a></td>';
                    tabStr += '</tr>';
                }

                $("#detailHostTeamTable2").html(tabStr);

                $("#hostTeamTable2").chromatable({
                    width: "100%",
                    height: $("#hostTeamDiv2").height(),
                    scrolling: "yes"
                });

            }
        }
    });

    // 客场
    postData = {
        "param":
            {
                "TeamId": teamId,
                "LeagueId": curLeagueId2,
                "SeasonId": curSeasonId2,
                "LastSeasonId": curLastSeasonId2,
                "HostOrGuest": 2
            }
    };

    $("#detailGuestTeamTable2").html("");

    $.ajax({
        type: "Post",
        url: "/RealTimeMatchs/GetNewMatchTeamInfos",
        data: postData,
        success: function (d) {
            if (d.success) {
                var data = d.data;
                var tabStr = '';
                var tempId = -1;
                for (var i = 0; i < data.length; i++) {
                    tabStr += '<tr>';
                    tabStr += '<td class="center">' + (i + 1) + '</td>';
                    tabStr += '<td class="center">' + data[i].matchTime + '</td>';
                    tabStr += '<td class="center"><a target="_blank" href="../TeamPlayInfo?teamId=' + data[i].hostTeamId + '&matchId=' + data[i].matchId + '">' + showTeamName(data[i].hostTeamId, data[i].hostTeamName) + '</a>[' + (data[i].hostTeamRank == 9999 ? "无":data[i].hostTeamRank) + ']</td>';
                    tabStr += '<td class="center">' + swapScores(data[i].hostScore, data[i].guestScore, data[i].hostHalfScore, data[i].guestHalfScore) + '</td>';
                    tabStr += '<td class="center">' + getWinOrLose(data[i].hostTeamId, data[i].guestTeamId, data[i].hostScore, data[i].guestScore) + '</td>';
                    tabStr += '<td class="center">' + swapOdds(data[i].winOdds, data[i].hostScore, data[i].guestScore, 3) + '</td>';
                    tabStr += '<td class="center">' + swapOdds(data[i].drowOdds, data[i].hostScore, data[i].guestScore, 1) + '</td>';
                    tabStr += '<td class="center">' + swapOdds(data[i].loseOdds, data[i].hostScore, data[i].guestScore, 0) + '</td>';

                    if (tempId != data[i].hostTeamId) {
                        tabStr += '<td class="center">' + data[i].hostAllCount + '</td>';
                        tabStr += '<td class="center">' + data[i].hostWinCount + '</td>';
                        tabStr += '<td class="center">' + data[i].hostDrawCount + '</td>';
                        tabStr += '<td class="center">' + data[i].hostLoseCount + '</td>';
                        tabStr += '<td class="center">' + data[i].hostInCount + '</td>';
                        tabStr += '<td class="center">' + data[i].hostOutCount + '</td>';
                        tabStr += '<td class="center">' + data[i].hostGoalCount + '</td>';
                        tabStr += '<td class="center"><font style="color:red;">' + data[i].hostIntegral + '</font></td>';
                    } else {
                        tabStr += '<td class="center"></td>';
                        tabStr += '<td class="center"></td>';
                        tabStr += '<td class="center"></td>';
                        tabStr += '<td class="center"></td>';
                        tabStr += '<td class="center"></td>';
                        tabStr += '<td class="center"></td>';
                        tabStr += '<td class="center"></td>';
                        tabStr += '<td class="center"></td>';
                    }
                    tempId = data[i].hostTeamId;

                    tabStr += '<td class="center"><a href="http://odds.500.com/fenxi/shuju-' + data[i].matchId + '.shtml" target="view_window">析</a></td>';
                    tabStr += '</tr>';
                }

                $("#detailGuestTeamTable2").html(tabStr);

                $("#guestTeamTable2").chromatable({
                    width: "100%",
                    height: $("#guestTeamDiv2").height(),
                    scrolling: "yes"
                });

            }
        }
    });
}

// 显示球队名称
function showTeamName(curTeamId, curTeamName) {

    if (curTeamId == teamId) {
        return '<font style="color:#B22222">' + curTeamName + '</font>';
    }
    return curTeamName;
}

// 胜负结果转换
function getWinOrLose(hostTeamId, guestTeamId, hostScore, guestScore) {

    if (hostScore < 0 || guestScore < 0) {
        return '<font></font>';
    }

    if (hostTeamId == teamId) {
        if (hostScore > guestScore) {
            return '<font style="color:red;">胜</font>';
        } else if (hostScore == guestScore) {
            return '<font style="color:green;">平</font>';
        } else {
            return '<font style="color:blue;">负</font>';
        }
    } else {
        if (hostScore < guestScore) {
            return '<font style="color:red;">胜</font>';
        } else if (hostScore == guestScore) {
            return '<font style="color:green;">平</font>';
        } else {
            return '<font style="color:blue;">负</font>';
        }
    }
    
}

// 赔率转换
function swapOdds(oddsNum, hostScore, guestScore,type) {
    var f = Math.round(oddsNum * 1) / 1000;
    if (f < 1) return "";
    var s = f.toString();
    var rs = s.indexOf('.');
    if (rs < 0) {
        rs = s.length;
        s += '.';
    }
    while (s.length <= rs + 2) {
        s += '0';
    }   

    if (hostScore < 0 || guestScore < 0) {
        return s;
    }

    if (type == 3) {
        if (hostScore > guestScore) {
            return '<font style="background-color:#EEEE00">'+s+'</font>';
        } 
       
    } else if (type == 1) {
        if (hostScore == guestScore) {
            return '<font style="background-color:#EEEE00">' + s + '</font>';
        }
    } else {
        if (hostScore < guestScore) {
            return '<font style="background-color:#EEEE00">' + s + '</font>';
        }
    }

    return s;
}


// 比分转换
function swapScores(hostScore, guestScore, hostHalfScore, guestHalfScore) {
    var s = '';
    if (hostScore < 0 || guestScore < 0) {
        return '<font></font>';
    }
    if (hostScore > guestScore) {
        s += '<font style="color:red;">' + hostScore + '</font>:' + guestScore;
    } else if (hostScore == guestScore) {
        s += '<font style="color:green;">' + hostScore + '</font>:<font style="color:green;">' + guestScore + '</font>';
    } else {
        s += '' + hostScore + ':<font style="color:red;">' + guestScore + '</font>' ;
    }
    return s;
}